<template>
	<!-- 公共底部导航栏 -->
  <view class="tabbar-container">
    <block>
      <!-- 针对中间的导航栏  通过true来判断控制类名和样式 -->
      <view class="tabbar-item" v-for="(item, index) in tabbarList" :class="[item.centerItem ? 'center-item' : '']" @click="changeItem(item)" :key="item.id">
       <view v-if="item.id ==0 || item.id ==2 " class="item-top">
          <image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
        </view>
				<view v-else class="item-top centerPadding">
				  <image class="center" :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
				</view>
        <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
          <text>{{ item.text }}</text>
        </view>
      </view>
    </block>
  </view>
</template>

<script>
// 组件的书写符合easycom规范 无需引入直接使用
export default {
  props: {
    currentItem: {
      type: Number,
      default:0
    }
  },
  data () {
    return {
      tabbarList: [
        {
          id: 0,
          path: '/pages/index/index',
          icon: '/static/image/icon1@3x.png',
          selectIcon: '/static/image/icon1-click@3x.png',
          text: '首页',
          centerItem: false
        },
        {
          id: 1,
          path: '/subPackagesA/pages/shaft/index',
          icon: '/static/image/midButton.png',
          selectIcon: '/static/image/midButton.png',
          text: '',
          // 通过类名class控制样式大小
          centerItem: true
        },
        {
          id: 2,
          path: '/pages/personalcenter/index',
          icon: '/static/image/icon3@3x.png',
          selectIcon: '/static/image/icon3-click@3x.png',
          text: '我的',
          centerItem: false
        }
      ]
    }
  },
  mounted () {
    // this.currentItem = this.currentPage
    // 隐藏原来的tabBar导航栏
    uni.hideTabBar()
  },
  methods: {
    changeItem (item) {
			console.log('点击底部導航欄', item)
   //    let _this = this
   //    _this.currentItem = item.id;
			// if(item.id==1){
			// 	uni.navigateTo({
			// 		url: item.path
			// 	})
			// }else{
			// 	uni.switchTab({
			// 	  url: item.path
			// 	})
			// }
    
				this.$emit('changeItem', item)
    }
  }
};
</script>
<style lang="less" scope>
view {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.tabbar-container {
  position: fixed;
  bottom: 0rpx;
  left: 0rpx;
  width: 100%;
  height: 135rpx;
  box-shadow: 0 0 5px #999;
  display: flex;
  align-items: center;
  padding: 5rpx 0;
  color: #999999;
	background-color: #fff;

  /* 针对tabbar的统一处理 */
  .tabbar-item {
    width: 33.33%;
    height: 100rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
	  .item-top.centerPadding{
			padding: 0 !important;
		}
    .item-top {
      width: 70rpx;
      height: 70rpx;
      padding: 10rpx;
			image.center{
				width: 100rpx !important;
				height: 100rpx !important;
			}
      image {
        width: 100%;
        height: 100%;
      }
    }
    // 未被选中的导航栏字体
    .item-bottom {
      font-size: 28rpx;
      width: 100%;
    }
    // 被选中的导航栏字体
    .item-active {
      color: #000;
    }
  }

  // 最中间的tabbar导航栏
  .center-item {
    display: block;
    position: relative;
    .item-top {
      flex-shrink: 0;
      width: 100rpx;
      height: 100rpx;
      position: absolute;
      top: -60rpx;
      left: calc(50% - 50rpx);
      border-radius: 50%;
      // box-shadow: 0 0 5px #999;
      // background-color: rgb(240, 63, 131);
    }
    .item-bottom {
      position: absolute;
      bottom: 5rpx;
    }
    .item-active {
      position: absolute;
      bottom: 5rpx;
      color: #1fff;
    }
  }
}
</style>